﻿#include "hellorua.h"
#include "ui_hellorua.h"

#include <QDebug>

HelloRua::HelloRua(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::HelloRua)
{
    ui->setupUi(this);

    qDebug() << "suppose sql database:" << QSqlDatabase::drivers();

    QSqlDatabase database;


    if (QSqlDatabase::contains("qt_sql_default_connection"))
    {

        database = QSqlDatabase::database("qt_sql_default_connection");
    }
    else
    {
        // 建立和SQlite数据库的连接
        database = QSqlDatabase::addDatabase("QSQLITE");
        // 设置数据库文件的名字
        database.setDatabaseName("apaper.sqlite3");
    }

    // 连接数据库

    bool ok = database.open();

    if (ok)
    {
        qDebug() << "database connect is ok";
    }
    else
    {
        qDebug() << "database connect is fail";
    }

}

HelloRua::~HelloRua()
{
    delete ui;

    database.close();
}

#include "setting.h"

void HelloRua::on_buttonSetting_clicked()
{
    Setting *setting = new Setting(database, this);
    setting->exec();
    delete setting;
}

